package com.example.controller;

import com.example.common.Result;
import com.example.entity.Pharmacy;
import com.example.service.PharmacyService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 张比特
 * @Data: 2024/8/27 下午3:36
 * @Version: v1.0.0
 * @Description: TODO
 **/
@RestController
@RequestMapping("/pharmacy")
public class PharmacyController {

    @Resource
    private PharmacyService pharmacyService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Pharmacy Pharmacy) {
        pharmacyService.add(Pharmacy);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        pharmacyService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Pharmacy Pharmacy) {
        pharmacyService.updateById(Pharmacy);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Pharmacy Pharmacy = pharmacyService.selectById(id);
        return Result.success(Pharmacy);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Pharmacy Pharmacy) {
        List<Pharmacy> list = pharmacyService.selectAll(Pharmacy);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Pharmacy Pharmacy,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Pharmacy> page = pharmacyService.selectPage(Pharmacy, pageNum, pageSize);
        return Result.success(page);
    }
}
